using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using DIS_DAL_WS.Models;

namespace DIS_DAL_WS.DTO
{
    [DataContract]
	public class DailyReportDTO
	{
        [DataMember]
		public int ID { get; set; }
        [DataMember]
		public int IDRestaurant { get; set; }
        [DataMember]
		public DateTime ReportDate { get; set; }
        [DataMember]
        public RestaurantDTO Restaurant { get; set; }

        public static DailyReportDTO Translate(DailyReport Entity)
        {
            if (Entity != null)
            {
                var dto = new DailyReportDTO
                {
                    ID = Entity.ID,
                    ReportDate = Entity.ReportDate == null ? DateTime.MinValue : Entity.ReportDate.Value,
                    Restaurant = RestaurantDTO.TranslateBase(Entity.Restaurant)
                };
                if (Entity.IDRestaurant != null)
                {
                    dto.IDRestaurant = Entity.IDRestaurant.Value;
                }
                else
                {
                    dto.IDRestaurant = -1;
                }
                return dto;
            }
            return null;
        }

        public static DailyReport Reverse(DailyReportDTO obj)
        {
            var entity = new DailyReport
            {
                ID = obj.ID,
                ReportDate = obj.ReportDate
            };
            if (obj.IDRestaurant != -1)
            {
                entity.IDRestaurant = obj.IDRestaurant;
            }
            return entity;
        }

        public void UpdateEntity(ref DailyReport entity)
        {
            entity.ReportDate = ReportDate;
            if (IDRestaurant != -1)
            {
                entity.IDRestaurant = IDRestaurant;
            }
        }
	}
}